var mobId, mob, stats, modified, MaxRandom, setupTask, ostats, victor, luck;
var 清怪 = false;
var 刷新地图 = true;
var 复活次数 = 11;
var 副本名称 = "贝勒德[困难]";
var 左臂 = 9390611;
var 左臂_血量倍率 = 3;
var 右臂 = 9390610;
var 右臂_血量倍率 = 3;
var 肚脐 = 9390612;
var 肚脐_血量倍率 = 3;
var 头1 = 9390600;
var 头1_血量倍率 = 1;
var 头2 = 9390601;
var 头2_血量倍率 = 1;
var 头3 = 9390602;
var 头3_血量倍率 = 1;
var 副本时限 = 1000 * 60 * 60;
var 实例地图 = [863000900, 863000910, 863010100, 863010200, 863010210, 863010220, 863010230, 863010240, 863010300, 863010310, 863010320, 863010330, 863010400, 863010410, 863010420, 863010430, 863010500, 863010600, 863000920, 863010700];
var 准备地图 = 863010000;
var 退场倒计时 = 180;

function init() {}

function setup(f, b) {
    em.setProperty("state", "1");
    em.setProperty("leader", "true");
    var d = em.newInstance(副本名称);
    for (var c = 0; c < 实例地图.length; c++) {
        var e = d.setInstanceMap(实例地图[c]);
        e.resetPQ(f);
        e.resetFully();
        e.killAllMonsters(清怪);
        e.respawn(刷新地图)
    }
    d.startEventTimer(副本时限);
    d.setProperty("FBtime", 副本时限);
    d.setProperty("FBname", 副本名称);
    d.setProperty("strMap", 准备地图);
    d.setProperty("左臂_血量", "" + em.getMonster(左臂).getMobMaxHp() * 左臂_血量倍率 + "");
    d.setProperty("右臂_血量", "" + em.getMonster(右臂).getMobMaxHp() * 右臂_血量倍率 + "");
    d.setProperty("肚脐_血量", "" + em.getMonster(肚脐).getMobMaxHp() * 肚脐_血量倍率 + "");
    d.setProperty("open", "1");
    d.setProperty("左臂", "0");
    d.setProperty("右臂", "0");
    d.setProperty("肚脐", "0");
    d.setProperty("核", "0");
    d.setProperty("头召唤情况", "0");
    mobId = 左臂;
    mob = em.getMonster(mobId);
    mob.setOverrideStats();
    mob.getChangedStats().hp = parseInt(d.getProperty("左臂_血量"));
    mob.getChangedStats().mp = 99000000;
    mob.heal();
    d.registerMonster(mob);
    var a = d.getMapInstance(实例地图[15]);
    a.spawnMonsterOnGroundBelow(mob, new java.awt.Point(84, 69));
    mobId = 右臂;
    mob = em.getMonster(mobId);
    mob.setOverrideStats();
    mob.getChangedStats().hp = parseInt(d.getProperty("右臂_血量"));
    mob.getChangedStats().mp = 99000000;
    mob.heal();
    d.registerMonster(mob);
    var a = d.getMapInstance(实例地图[11]);
    a.spawnMonsterOnGroundBelow(mob, new java.awt.Point(3, 69));
    mobId = 肚脐;
    mob = em.getMonster(mobId);
    mob.setOverrideStats();
    mob.getChangedStats().hp = parseInt(d.getProperty("肚脐_血量"));
    mob.getChangedStats().mp = 99000000;
    mob.heal();
    d.registerMonster(mob);
    var a = d.getMapInstance(实例地图[7]);
    a.spawnMonsterOnGroundBelow(mob, new java.awt.Point(3, 69));
    return d
}

function onPlayerRegistered(b, a) {
    var c = b.getMapInstance(实例地图[0]);
    a.dropMessage(6, "[" + 副本名称 + "] 进入到了挑战地图，请小心行事。");
    a.changeMap(c, c.getPortal(0));
    a.setReviveCount(复活次数);
    a.getAPI().setNumberForQuestInfo(准备地图, "damage", 0)
}

function onPlayerRevived(b, a) {
    if (a.getReviveCount() > 0) {
        return true
    } else {
        var c = b.getMapFactoryMap(准备地图);
        a.changeMap(c, c.getPortal(0));
        return true
    }
}

function onPlayerKilled(b, a) {
    if (a.getReviveCount() > 0) {
        a.addHP(500000);
        a.dropMessage(-1, "艾尔达之力使你复活");
        return true
    } else {
        var c = b.getMapFactoryMap(准备地图);
        a.changeMap(c, c.getPortal(0));
        return true
    }
}

function onMapChanged(f, e, d) {
    if (实例地图.indexOf(d) < 0) {
        on玩家退场(f, e, false);
        return
    }
    switch (d) {
        case 实例地图[0]:
            break;
        case 实例地图[1]:
            break;
        case 实例地图[2]:
            break;
        case 实例地图[3]:
            break;
        case 实例地图[4]:
            break;
        case 实例地图[5]:
            break;
        case 实例地图[6]:
            break;
        case 实例地图[7]:
            break;
        case 实例地图[8]:
            break;
        case 实例地图[9]:
            break;
        case 实例地图[10]:
            break;
        case 实例地图[11]:
            break;
        case 实例地图[12]:
            break;
        case 实例地图[13]:
            break;
        case 实例地图[14]:
            break;
        case 实例地图[15]:
            break;
        case 实例地图[16]:
            f.setProperty("open", "2");
            break;
        case 实例地图[17]:
            var c = parseInt(f.getProperty("头召唤情况"));
            if (f.getMapInstance(e.getMapId()).getNumMonsters() == 0 && c == 0) {
                var b = parseInt(f.getProperty("右臂")) + parseInt(f.getProperty("左臂")) + parseInt(f.getProperty("肚脐"));
                switch (b) {
                    case 0:
                        f.setProperty("头1_血量", "" + em.getMonster(头1).getMobMaxHp() * 60 + "");
                        mobId = 头1;
                        mob = em.getMonster(mobId);
                        mob.setOverrideStats();
                        mob.getChangedStats().hp = parseInt(f.getProperty("头1_血量"));
                        mob.getChangedStats().mp = 99000000;
                        mob.getChangedStats().level = 250;
                        mob.heal();
                        f.registerMonster(mob);
                        var a = f.getMapInstance(实例地图[17]);
                        a.spawnMonsterOnGroundBelow(mob, new java.awt.Point(7, 61));
                        f.setProperty("头召唤情况", "3");
                        break;
                        return;
                    case 1:
                        f.setProperty("头1_血量", "" + em.getMonster(头1).getMobMaxHp() * 30 + "");
                        mobId = 头1;
                        mob = em.getMonster(mobId);
                        mob.setOverrideStats();
                        mob.getChangedStats().hp = parseInt(f.getProperty("头1_血量"));
                        mob.getChangedStats().mp = 99000000;
                        mob.getChangedStats().level = 230;
                        mob.heal();
                        f.registerMonster(mob);
                        var a = f.getMapInstance(实例地图[17]);
                        a.spawnMonsterOnGroundBelow(mob, new java.awt.Point(7, 61));
                        f.setProperty("头召唤情况", "2");
                        break;
                        return;
                    case 2:
                        f.setProperty("头1_血量", "" + em.getMonster(头1).getMobMaxHp() * 10 + "");
                        mobId = 头1;
                        mob = em.getMonster(mobId);
                        mob.setOverrideStats();
                        mob.getChangedStats().hp = parseInt(f.getProperty("头1_血量"));
                        mob.getChangedStats().mp = 99000000;
                        mob.getChangedStats().level = 210;
                        mob.heal();
                        f.registerMonster(mob);
                        var a = f.getMapInstance(实例地图[17]);
                        a.spawnMonsterOnGroundBelow(mob, new java.awt.Point(7, 61));
                        f.setProperty("头召唤情况", "1");
                        break;
                        return;
                    case 3:
                        f.setProperty("头1_血量", "" + em.getMonster(头1).getMobMaxHp() * 1 + "");
                        mobId = 头1;
                        mob = em.getMonster(mobId);
                        mob.setOverrideStats();
                        mob.getChangedStats().hp = parseInt(f.getProperty("头1_血量"));
                        mob.getChangedStats().mp = 99000000;
                        mob.getChangedStats().level = 180;
                        mob.heal();
                        f.registerMonster(mob);
                        var a = f.getMapInstance(实例地图[17]);
                        a.spawnMonsterOnGroundBelow(mob, new java.awt.Point(7, 61));
                        f.setProperty("头召唤情况", "1");
                        break;
                        return
                }
            }
            break;
        case 实例地图[18]:
            break;
        case 实例地图[19]:
            break
    }
}

function onMonsterKilled(f, h) {
    var g = f.getMapInstance(实例地图[15]);
    var b = f.getMapInstance(实例地图[11]);
    var d = f.getMapInstance(实例地图[7]);
    switch (h) {
        case 左臂:
            f.setProperty("左臂", "1");
            g.getWeatherEffectNotice("左臂破碎了，连宝物一起碎了。贝勒德更加虚弱了。", 265, 8000, 1);
            player.getAPI().贝勒德_动画("phase3", 1);
            player.getAPI().贝勒德_动画("clear", 1);
            break;
        case 右臂:
            b.getWeatherEffectNotice("右臂破碎了，连宝物一起碎了。贝勒德更加虚弱了。", 265, 8000, 1);
            f.setProperty("右臂", "1");
            player.getAPI().贝勒德_动画("phase3", 1);
            player.getAPI().贝勒德_动画("clear", 1);
            break;
        case 肚脐:
            d.getWeatherEffectNotice("肚脐破碎了，连宝物一起碎了。贝勒德更加虚弱了。", 265, 8000, 1);
            f.setProperty("肚脐", "1");
            player.getAPI().贝勒德_动画("clear1", 1);
            player.getAPI().贝勒德_动画("clear2", 1);
            break;
        case 头1:
            h = 头2;
            f.setProperty("头2_血量", "" + em.getMonster(头1).getMobMaxHp() * 6 + "");
            mob = em.getMonster(h);
            mob.setOverrideStats();
            mob.getChangedStats().hp = parseInt(f.getProperty("头2_血量"));
            mob.getChangedStats().mp = 99000000;
            mob.getChangedStats().level = 200;
            mob.heal();
            f.registerMonster(mob);
            var a = f.getMapInstance(实例地图[17]);
            a.spawnMonsterOnGroundBelow(mob, new java.awt.Point(7, 61));
            a.getWeatherEffectNotice("贝勒德的嘴巴瘫痪了。请攻击眼睛。", 265, 3000, 1);
            player.getAPI().贝勒德_动画("phase2-1", 1);
            player.getAPI().贝勒德_动画("phase2-2", 1);
            break;
        case 头2:
            f.setProperty("头3_血量", "" + em.getMonster(头1).getMobMaxHp() * 6 + "");
            h = 头3;
            mob = em.getMonster(h);
            mob.setOverrideStats();
            mob.getChangedStats().hp = parseInt(f.getProperty("头3_血量"));
            mob.getChangedStats().mp = 99000000;
            mob.getChangedStats().level = 200;
            mob.heal();
            f.registerMonster(mob);
            var a = f.getMapInstance(实例地图[17]);
            a.spawnMonsterOnGroundBelow(mob, new java.awt.Point(7, 61));
            a.getWeatherEffectNotice("眼睛瘫痪了。破坏掉额头上的核心，就能击败贝勒德。", 265, 3000, 1);
            player.getAPI().贝勒德_动画("phase3", 1);
            break;
        case 头3:
            f.getPlayers().forEach(function (i) {
                i.scheduleWarpTask(3, 实例地图[19], 0, false)
            });
            var c = parseInt(f.getProperty("左臂_血量")) + parseInt(f.getProperty("右臂_血量")) + parseInt(f.getProperty("肚脐_血量")) + parseInt(f.getProperty("头1_血量")) + parseInt(f.getProperty("头2_血量")) + parseInt(f.getProperty("头3_血量"));
            f.setProperty("BOSShp", c);
            openNpc(f, 9130027, "评价系统");
            f.startEventTimer(退场倒计时 * 1000);
            for (var e = 0; e < f.getPlayerCount(); e++) {
                f.getPlayers().get(e).dropMessage(6, "[" + 副本名称 + "] 挑战成功！已召唤击杀奖励！！")
            }
            break;
        default:
            if (f.getMapInstance(player.getMapId()).getNumMonsters() == 0) {
                f.getPlayers().forEach(function (i) {
                    i.getAPI().fieldEffect_ScreenMsg("monsterPark/clear");
                    i.getAPI().fieldEffect_PlayFieldSound("Party1/Clear", 100)
                })
            } else {
                f.getPlayers().forEach(function (i) {
                    i.dropMessage(-1, "现在……这一地区还剩下" + f.getMapInstance(i.getMapId()).getNumMonsters() + "个邪恶气息。")
                })
            }
            break
    }
    return 1
}

function onMonsterDamaged(b, a, d, e, c) {
    if (d == 左臂 || d == 右臂 || d == 肚脐 || d == 头1 || d == 头2 || d == 头3) {
        a.getAPI().addNumberForQuestInfo(准备地图, "damage", e)
    }
}

function openNpc(c, b, d) {
    for (var a = 0; a < c.getPlayerCount(); a++) {
        c.getPlayers().get(a).getAPI().openNpc(b, d)
    }
}

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
}

function initProp(a, b) {
    if (em.getProperty(a) == null) {
        em.setProperty(a, b)
    }
}

function initPropArray(a, d, c, e) {
    for (var b = c; b <= e; b++) {
        if (em.getProperty(a + "_" + b) == null) {
            em.setProperty(a + "_" + b, d)
        }
    }
}

function initPropArrayRandom(a, d, j, b, h) {
    var g = new Array();
    var k = h - b + 1;
    var c = (j - d) < (h - b) ? true : false;
    do {
        var f = randomNum(d, j);
        if (c || g.indexOf(f) < 0) {
            g.push(f);
            k--
        }
    } while (k);
    for (var e = b; e <= h; e++) {
        if (em.getProperty(a + "_" + e) == null) {
            em.setProperty(a + "_" + e, g[e - 1])
        }
    }
}

function on玩家退场(c, b, a) {
    c.disposeIfPlayerBelow(a ? 999 : 0, 准备地图);
    em.getProperties().clear();
    em.setProperty("state", 0);
    em.setProperty("leader", "true");
    c.unregisterPlayer(b)
}

function onPartyDisbanded(a) {
    on玩家退场(a, player, false)
}

function onTimeOut(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, false);
    return 0
}

function onItemPickedUp(b, a, c) {};